import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    redirect: '/index'
  },
  {
    path: '/index',
    name: 'Index',
    component: () => import('../views/Index/index.vue'),
    meta: {
      auth: false,
      title: '首页',
      keepAlive: true
    }
  },
  {
    path: '/lending',
    name: 'Lending',
    component: () => import('../views/lending/index.vue'),
    meta: {
      auth: false,
      title: '借贷订单',
      keepAlive: false
    }
  },
  {
    path: '/lever',
    name: 'Lever',
    component: () => import('../views/lever/index.vue'),
    meta: {
      auth: false,
      title: '杠杆借贷',
      keepAlive: false
    }
  },
  {
    path: '/project',
    name: 'project',
    component: () => import('../views/project/index.vue'),
    meta: {
      auth: false,
      title: '热门项目',
      keepAlive: false
    },
    // children: [
    //   {
    //     path: 'detail',
    //     name: 'detail',
    //     component: () => import('../views/hotProject/detail.vue'),
    //     meta: {
    //       auth: false,
    //       title: '借贷订单',
    //       keepAlive: false
    //     }
    //   }
    // ]
  },
  {
    path: '/detail',
    name: 'detail',
    component: () => import('../views/project/detail.vue'),
    meta: {
      auth: false,
      title: '热门项目内页',
      keepAlive: false
    }
  },
  {
    path: '/finance',
    name: 'Finance',
    component: () => import('../views/finance/index.vue'),
    meta: {
      auth: false,
      title: '高端理财',
      keepAlive: false
    }
  },
  {
    path: '/bill',
    name: 'bill',
    component: () => import('../views/finance/bill.vue'),
    meta: {
      auth: false,
      title: '账单',
      keepAlive: false
    }
  },
  {
    // 匹配所有路径  vue2使用*   vue3使用/:pathMatch(.*)*或/:pathMatch(.*)或/:catchAll(.*)
    path: '/:pathMatch(.*)*',
    name: '404',
    redirect: '/index.html'
  }
]
const modulesFiles = import.meta.glob('./modules/*.js', { eager: true })
//自动引入module包
const moduleRoutes = Object.entries(modulesFiles).reduce((moduleRoutes, [modulePath, value]) => {
  return [...moduleRoutes, ...value.default]
}, [])

const router = createRouter({
  history: createWebHashHistory(),
  routes: [...routes, ...moduleRoutes]
})
export default router
